<?php //echo "<pre>"; print_r($selectedUser);die();?>
<?php $this -> load -> view('header'); ?>
<!-- BEGIN CONTAINER -->
<div class="page-container row-fluid">
	<?php //$this->load->view('sidebar');?>
	<!-- BEGIN PAGE -->
	<div class="page-content">
		<!-- BEGIN PAGE CONTAINER-->
		<div class="container-fluid">
			<!-- BEGIN PAGE HEADER-->
			<div class="row-fluid">
				<div class="span12">
					<!-- BEGIN PAGE TITLE & BREADCRUMB-->
					<h3 class="page-title"> Pengaturan</h3>
					<?php $this -> load -> view('breadcrumb'); ?>
					<!-- END PAGE TITLE & BREADCRUMB-->
				</div>
			</div>
			<!-- END PAGE HEADER-->
			<div class="row-fluid">
				<div class="span4">
					<!-- BEGIN EXAMPLE TABLE PORTLET-->
					<div class="portlet box blue">
						<div class="portlet-title">
							<h4><i class="icon-edit"></i>Tambah Distrik</h4>
							<!--<div class="tools" >
								<a href="javascript:;" class="reload"></a>
							</div>-->
						</div>
						<div class="portlet-body">
							<form id="userForm" action="<?php echo base_url()?>administration/saveDistrik" method="post" class="form-horizontal">
							<input type="hidden" name="Distrik.id" value="<?php if($distrik != null) echo $distrik->getId(); else echo '';?>"/>
					           <div class="control-group">
					              <label class="control-label">Nama Distrik</label>
					              <div class="controls">
					                  <input type="text" class="span12" name="Distrik.nama" id="pDistrikNama" value="<?php if($distrik != null) echo $distrik->getNama(); else echo '';?>"/>                  
					              </div>
					           </div>
							   <div class="control-group">
					                <label class="control-label">Nama Propinsi</label>
					                   <div class="controls">
					                     <select class="span12 chosen" data-placeholder="--Pilih Propinsi--" name="Distrik.propinsi" tabindex="1" id="pPropinsi">
					                        <option value="-1">--Pilih Propinsi--</option>
					                        <?php
					                        	foreach ($propinsis as $propinsi){
					                        		if ($selectedDistrik != NULL){
					                        			if ($selectedDistrik->getPropinsi() == $propinsi){
					                        				echo '<option value="'.$propinsi->getId().'" selected>'.$propinsi->getNama().'</option>';
					                        			} else {
					                        				echo '<option value="'.$propinsi->getId().'" >'.$propinsi->getNama().'</option>';
					                        			}
					                        		} else {
					                        			echo '<option value="'.$propinsi->getId().'" >'.$propinsi->getNama().'</option>';
					                        		}
					                        	}
					                        ?>					                        
					                 	 </select>
					              </div>
					           </div>
					           <div class="form-actions">
									<button type="submit" class="btn blue" id="saveBtn">
										<i class="icon-ok"></i> Simpan
									</button>
									<button type="button" class="btn" id="cancelBtn">
											Batal
									</button>
								</div>
					       </form>
						</div>
					</div>
					<!-- END EXAMPLE TABLE PORTLET-->
				</div>
				<div class="span8">

					<!-- BEGIN EXAMPLE TABLE PORTLET-->
					<div class="portlet box blue">
						<div class="portlet-title">
							<h4><i class="icon-edit"></i>Daftar Distrik</h4>
							<!--<div class="tools" >
								<a href="javascript:;" class="reload"></a>
							</div>-->
							<div class="actions" style="padding-right: 0px">
								<a href="<?php echo base_url()?>report/rekapDistrik" class="btn green"><i class="icon-print"></i> Export To Excel</a>
							</div>								
							<div class="actions" style="padding-right: 0px">
							<!--	<a href="" id="addUserBtn" class="btn green"><i class="icon-plus"></i> Tambah Pengguna</a> -->
							</div>
							
						</div>
						<div class="portlet-body">
							<?php //$this->load->view('searchBar', $searchBar);?>
								<table class="table table-striped table-hover table-bordered" id="daftarDistrik">
								<thead>
									<tr>
										<th>Nama Distrik</th>
										<th>Nama Propinsi</th>
										<th>Tindakan</th>
									</tr>
								</thead>
								<tbody>
									
									<?php 
										foreach ($distriks as $distrik){
											echo '<tr>
													<td>'.$distrik->getNama().'</td>
													<td>';
													if($distrik->getPropinsi() == null)
													{
															echo '-';
													}
													else
													{
														echo $distrik->getPropinsi()->getNama();
													}
											echo '</td>
													<td>
														<a class="btn blue mini" href="'.base_url().'administration/distrikList/'.$distrik->getId().'">Edit</a>&nbsp;
														<!-- <a class="btn red mini" href="">Hapus</a> -->
													</td>
												</tr>';		
										}
									
									?>
																	
								</tbody>
							</table>
							<div class="row-fluid">
								<?php //$this->load->view('paging', $pBerkas);?>
							</div>
						</div>
					</div>
					<!-- END EXAMPLE TABLE PORTLET-->
				</div>
			</div>
		</div>
		<!-- END PAGE CONTAINER-->
	</div>
	<!-- END PAGE -->
</div>
<!-- END CONTAINER -->

<!-- DIALOG -->
<!--
<div id="addUserModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
		<h3 id="myModalLabel1">Tambah Pengguna</h3>		
	</div>
<div class="modal-body">
	<div class="portlet-body fuelux">
		<form action="#" class="form-horizontal">
           <div class="control-group">
              <label class="control-label">Nama Pengguna</label>
              <div class="controls">
                  <input type="text" class="span3" />                  
              </div>
           </div>
           <div class="control-group">
                <label class="control-label">Jabatan</label>
                              <div class="controls">
                                 <select class="span3 chosen" data-placeholder="--Pilih Jabatan--" tabindex="1">
                                    <option value=""></option>
                                    <option value="Category 1">CBO</option>
                                    <option value="Category 2">CF</option>
                                    <option value="Category 3">DQA</option>
                                    <option value="Category 4">Koordinator IT</option>
                 				</select>
              </div>
           </div>
           <div class="control-group">
                <label class="control-label">Jabatan</label>
                <div class="controls">
                   <select data-placeholder="Jabatan" class="chosen span3" tabindex="-1" id="selS0V">
                      <option value=""></option>
                      <optgroup label="Profil Inbox">
                      	<option>Dallas Cowboys</option>
                      	<option>New York Giants</option>
                      	<option>Philadelphia Eagles</option>
                      	<option>Washington Redskins</option>
                      </optgroup>
                      <optgroup label="Profil Administrasi Berkas">
                      	<option>Chicago Bears</option>
                        <option>Detroit Lions</option>
                        <option>Green Bay Packers</option>
                        <option>Minnesota Vikings</option>
                      </optgroup>
					</select>
                </div>
           </div>
       </form>                 
	</div>	
</div>
	<div class="modal-footer">
		<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
		<button class="btn yellow" id="saveNote">Save</button>
	</div>
</div>-->
<!-- END DIALOG -->
<!--
<div id="cancelModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
		<h3 id="myModalLabel3">Confirm Header</h3>
	</div>
	<div class="modal-body">
		<p>Apakah anda yakin membatalkan laporan ini ?</p>				
	</div>
	<div class="modal-footer">
		<button class="btn" data-dismiss="modal" aria-hidden="true">Tidak</button>
		<button data-dismiss="modal" class="btn blue" id="confirmCancelBtn">Ya</button>
	</div>
</div>
-->	
<?php $this->load->view('footer')?>

<script>
	$(document).ready(function() {
		oTable = $('#daftarDistrik').dataTable({
	          "bProcessing" : true,
	          "bScrollCollapse" : true,
	          "bSort" : true,
	            "iDisplayLength": 10,
	            "sPaginationType": "bootstrap",
	            "oLanguage": {
	                "sLengthMenu": "_MENU_ Distrik per halaman",
	                "oPaginate": {
	                    "sPrevious": "Prev",
	                    "sNext": "Next"
	                }
	            },
	            "order": [[ 1, "asc" ]]
	        });
        
		$("#addUserModal").draggable({
		      handle: ".modal-header"
		}); 
		 
		$("#addUserModal" ).dialog({
		      height: 300,
		      width: 400,
		      modal: true
		 }); 
		$('#cancelBtn').click(function (event){			
			event.preventDefault();
			$('#pUserId').val("");
			$('#pPassword').val("");
			$('#pJabatan').val("-1");
			$('#pJabatan').trigger("liszt:updated");
			//$("#pProfil").multiselect("clearSelection");
			//$("#pProfil").multiselect( 'refresh' );
			//$("#pProfil > option").attr("selected",false);
			$("#pProfil option:selected").removeAttr("selected");
			$('#pProfil').trigger("liszt:updated");		
			window.location="<?php echo base_url().'administration/distrikList';?>"	
		});
		
	/*	$('#pUserId').keypress(function (e) {
		    var regex = new RegExp("^[a-zA-Z0-9]+$");
		    var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
		    if (regex.test(str)) {
		        return true;
		    }
		    e.preventDefault();
		    return false;
	}); */
		
		$('#saveBtn').click(function(event){
			/*  validasi */
			event.preventDefault();
			/*if ($('#distrik').val() == "-1"){
				alert('District cannot be null...');
				return;
			}*/
			if ($('#pUserId').val() == ""){
				alert('Silahkan memasukkan nama pengguna');
				return;
			}
			
			if ($('#pUserId').val() == ""){
				alert('Silahkan memasukkan nama pengguna');
				return;
			}
			
			
	  		$('#userForm').submit();
	  	});
	});
</script>